#!/usr/bin/python
  
from ctypes import *
import os

'''
original data type in C header file -->
typedef struct __data_struct_type
{
	char c;
	char c_buf[64];
	char* c_ptr;
	int i;
	unsigned int ui;
	long li;
	unsigned long uli;
	float f;
	double lf;
	void* vp;
}DATST_TYPE;
'''

'''
 In Python, define structure type parameter must use keywork
 'class xxx(Structure)[]'
'''
class DATST_TYPE(Structure):
	_fields_ = [
		("c", c_char),
		("c_buf", c_char*64),
		("c_ptr", c_char_p),
		("i", c_int),
		("ui", c_uint),
		("li", c_long),
		("uli", c_ulong),
		("f", c_float),
		("lf", c_double),
		("func", c_void_p)
	 ]

def vfunc():
	print 2**6

#import C shared library 'Cfunc.so' & named 'libCfunc'
libCfunc = cdll.LoadLibrary("./Cfunc.so") 

#vfunc()

#Define Class type variable & initialize all members in data struct.
ds = DATST_TYPE()
ds.c = 'j'
ds.c_buf = "jinquan"
ds.c_ptr = "mantou"
ds.i = -123
ds.ui = 3000
ds.li = -77
ds.uli = 7000000
ds.f = -5.1
ds.lf = 3.1415927
#ds.func = byref(vfunc())


#declare C function 'display_datst_arg' argments' data type is 'DATST_TYPE'.
libCfunc.display_datst_arg.argtypes = [DATST_TYPE]
#declare C function 'display_datst_ptr_arg' argments' data type is 'DATST_TYPE' POINTER.
libCfunc.display_datst_ptr_arg.argtypes = [POINTER(DATST_TYPE)]

#Call C function 'display_datst_arg' with instance argment in shared library 'Cfunc.so'
print "Call C function with Class instance argment ."
libCfunc.display_datst_arg(ds)
print "\n"

print "Call C function with Class POINTER argment ->"
#Call C function 'display_datst_arg' with POINTER argment in shared library 'Cfunc.so'
libCfunc.display_datst_ptr_arg(byref(ds))
print "\n"